﻿<%@ Page Title="Promotion Engine - Company Profile" Language="C#" MasterPageFile="~/Site.Master"
    AutoEventWireup="true" CodeBehind="CompanyProfile.aspx.cs" Inherits="PromotionEngine.CompanyProfile" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <script type="text/javascript">
        var oCompany = {};
        var PointExpireFixedDate, PointExpireDays;
        $(document).ready(function () {
            var today = new Date();
            PointExpireFixedDate = $("#PointExpireFixedDate").kendoDateTimePicker({
                value: new Date()
            }).data("kendoDateTimePicker");
            PointExpireDays = $("#PointExpireDays").kendoNumericTextBox({
                format: "n",
                decimals: 2,
                value: 0
            }).data("kendoNumericTextBox");

            var PointExpireType = $("#PointExpireType").kendoDropDownList({
                autoBind: false,
                filter: "contains",
                optionLabel: "[Select Point Expire Type]",
                dataTextField: "ReferenceName",
                dataValueField: "ReferenceValue",
                suggest: true,
                required: true,
                dataSource: {
                    transport: {
                        read: {
                            type: "GET",
                            url: "CompanyProfile.aspx/GetAllReference",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json"
                        },
                        parameterMap: function (data, operation) {
                            if (operation === "read") {
                                return { referenceCode: kendo.stringify('PointExpireType') };
                            }
                        }
                    },
                    type: "odata", //Important!!!!
                    schema: {
                        data: function (a) {
                            if (a.d != null) {
                                var data = a.d;
                                return data;
                            }
                        },
                        allowCustomValues: false,
                        model: {
                            id: "ReferenceValue",
                            fields: {
                                ReferenceValue: { type: "string", validation: { required: true} },
                                ReferenceName: { type: "string", validation: { required: true} }
                            }
                        }
                    }
                }
            });
            var PointConflictMethod = $("#PointConflictMethod").kendoDropDownList({
                autoBind: false,
                filter: "contains",
                optionLabel: "[Select Point Conflict Method]",
                dataTextField: "ReferenceName",
                dataValueField: "ReferenceValue",
                suggest: true,
                required: true,
                dataSource: {
                    transport: {
                        read: {
                            type: "GET",
                            url: "CompanyProfile.aspx/GetAllReference",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json"
                        },
                        parameterMap: function (data, operation) {
                            if (operation === "read") {
                                return { referenceCode: kendo.stringify('PointConflictMethod') };
                            }
                        }
                    },
                    type: "odata", //Important!!!!
                    schema: {
                        data: function (a) {
                            if (a.d != null) {
                                var data = a.d;
                                return data;
                            }
                        },
                        allowCustomValues: false,
                        model: {
                            id: "ReferenceValue",
                            fields: {
                                ReferenceValue: { type: "string", validation: { required: true} },
                                ReferenceName: { type: "string", validation: { required: true} }
                            }
                        }
                    }
                }
            });
            var PromotionConflictMethod = $("#PromotionConflictMethod").kendoDropDownList({
                autoBind: false,
                filter: "contains",
                optionLabel: "[Select Promotion Conflict Method]",
                dataTextField: "ReferenceName",
                dataValueField: "ReferenceValue",
                suggest: true,
                required: true,
                dataSource: {
                    transport: {
                        read: {
                            type: "GET",
                            url: "CompanyProfile.aspx/GetAllReference",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json"
                        },
                        parameterMap: function (data, operation) {
                            if (operation === "read") {
                                return { referenceCode: kendo.stringify('PromotionConflictMethod') };
                            }
                        }
                    },
                    type: "odata", //Important!!!!
                    schema: {
                        data: function (a) {
                            if (a.d != null) {
                                var data = a.d;
                                return data;
                            }
                        },
                        allowCustomValues: false,
                        model: {
                            id: "ReferenceValue",
                            fields: {
                                ReferenceValue: { type: "string", validation: { required: true} },
                                ReferenceName: { type: "string", validation: { required: true} }
                            }
                        }
                    }
                }
            });
            var PointChangeAction = $("#PointChangeAction").kendoDropDownList({
                autoBind: false,
                filter: "contains",
                optionLabel: "[Select Point Change Action]",
                dataTextField: "ReferenceName",
                dataValueField: "ReferenceValue",
                suggest: true,
                required: true,
                dataSource: {
                    transport: {
                        read: {
                            type: "GET",
                            url: "CompanyProfile.aspx/GetAllReference",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json"
                        },
                        parameterMap: function (data, operation) {
                            if (operation === "read") {
                                return { referenceCode: kendo.stringify('PointChangeAction') };
                            }
                        }
                    },
                    type: "odata", //Important!!!!
                    schema: {
                        data: function (a) {
                            if (a.d != null) {
                                var data = a.d;
                                return data;
                            }
                        },
                        allowCustomValues: false,
                        model: {
                            id: "ReferenceValue",
                            fields: {
                                ReferenceValue: { type: "string", validation: { required: true} },
                                ReferenceName: { type: "string", validation: { required: true} }
                            }
                        }
                    }
                }
            });
            var GradeMethod = $("#GradeMethod").kendoDropDownList({
                autoBind: false,
                filter: "contains",
                optionLabel: "[Select Grade Method]",
                dataTextField: "ReferenceName",
                dataValueField: "ReferenceValue",
                suggest: true,
                required: true,
                dataSource: {
                    transport: {
                        read: {
                            type: "GET",
                            url: "CompanyProfile.aspx/GetAllReference",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json"
                        },
                        parameterMap: function (data, operation) {
                            if (operation === "read") {
                                return { referenceCode: kendo.stringify('GradeMethod') };
                            }
                        }
                    },
                    type: "odata", //Important!!!!
                    schema: {
                        data: function (a) {
                            if (a.d != null) {
                                var data = a.d;
                                return data;
                            }
                        },
                        allowCustomValues: false,
                        model: {
                            id: "ReferenceValue",
                            fields: {
                                ReferenceValue: { type: "string", validation: { required: true} },
                                ReferenceName: { type: "string", validation: { required: true} }
                            }
                        }
                    }
                }
            });
            GetCompanyInfor();
        });
        function GetCompanyInfor() {
            $.ajax({
                type: "POST",
                url: "Company.aspx/GetCompanyByCode",
                data: '',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) {
                    var result = JSON.parse(response.d);
                    if (result.Table) {
                        var oCompany = result.Table;
                        if (oCompany.length > 0) {
                            oCompany = oCompany[0];
                            setValueTextBox(oCompany);
                            $("#PointExpireType").data("kendoDropDownList").value(oCompany.PointExpireType);
                            $("#PointConflictMethod").data("kendoDropDownList").value(oCompany.ConflictMethod);
                            $("#PromotionConflictMethod").data("kendoDropDownList").value(oCompany.PromotionConflictMethod);
                            $("#PointChangeAction").data("kendoDropDownList").value(oCompany.PointChangeAction);
                            $("#GradeMethod").data("kendoDropDownList").value(oCompany.GradeMethod);
                            $("#Address").text(oCompany.Address);
                            $("#CompanyCode").text(oCompany.CompanyCode);
                            $("#CompanyName").text(oCompany.CompanyName);
                            PointExpireFixedDate.value(kendo.parseDate(oCompany.PointExpireFixedDate));
                            PointExpireDays.value(oCompany.PointExpireDays);
                        }
                    }
                },
                failure: function (response) {
                    alert(response.d);
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    if (jqXHR.status == 500) {
                        alert('Internal error: ' + jqXHR.responseText);
                    } else {
                        alert('Unexpected error.' + jqXHR.responseText);
                    }
                }
            });
        }
        function UpdateConpanyProfile() {
            $("#errMsgProfile").text('');
            if ($("#ContactPerson").val() == '') {
                $("#errMsgProfile").css('color', 'red');
                $("#errMsgProfile").text('Please input Contact Person');
                return;
            }
            if ($("#ContactPhone").val() == '') {
                $("#errMsgProfile").css('color', 'red');
                $("#errMsgProfile").text('Please input Contact Phone');
                return;
            }
            if ($("#Address").val() == '') {
                $("#errMsgProfile").css('color', 'red');
                $("#errMsgProfile").text('Please input Address');
                return;
            }

            var listTextBox = $("input:text");
            for (var i = 0; i < listTextBox.length; i++) {
                var name = listTextBox[i].name;
                if (name.length > 0) {
                    oCompany[name] = $("[name=" + name + "]").val();
                }
            }
            oCompany.Address = $("#Address").text();
            oCompany.PointExpireFixedDate = new Date();
            $.ajax({
                type: "POST",
                url: "CompanyProfile.aspx/UpdateCompanyProfile",
                data: JSON.stringify({
                    oCompany: JSON.stringify(oCompany)
                }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    if ($.isNumeric(data.d)) {
                        $("#errMsgProfile").css('color', 'blue');
                        $("#errMsgProfile").text("Operation complete successful!");
                    }
                    else {
                        $("#errMsgProfile").css('color', 'red');
                        $("#errMsgProfile").text(data.d);
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    if (jqXHR.status == 500) {
                        alert('Internal error: ' + jqXHR.responseText);
                    } else {
                        alert('Unexpected error.' + jqXHR.responseText);
                    }
                }
            });

        }
        function UpdateConpanySetting() {
            $("#errMsgSetting").text('');
            var validator = $("#aspnetForm").kendoValidator().data("kendoValidator");
            if (validator.validate()) {
                getValueTextBox(oCompany);
                $.ajax({
                    type: "POST",
                    url: "CompanyProfile.aspx/UpdateCompanySetting",
                    data: JSON.stringify({
                        oCompany: JSON.stringify(oCompany)
                    }),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        if ($.isNumeric(data.d)) {
                            $("#errMsgSetting").css('color', 'blue');
                            $("#errMsgSetting").text("Operation complete successful!");
                        }
                        else {
                            $("#errMsgSetting").css('color', 'red');
                            $("#errMsgSetting").text(data.d);
                        }
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        if (jqXHR.status == 500) {
                            alert('Internal error: ' + jqXHR.responseText);
                        } else {
                            alert('Unexpected error.' + jqXHR.responseText);
                        }
                    }
                });
            }
        }
    </script>
    <table style="width: 100%;" border="0">
        <tr>
            <td align="left" style="width: 40%;"  valign="top">
                <div id="sidebar">
                    <div id="profile" class="widget">

                        <h3 class="style2">
                             Company Profile</h3>
                        <div>
                            <table border="0" style="width: 100%;">
                                <tr style="height: 30px;">
                                    <td class="k-tooltip-bottom" style="width: 130px;">
                                        Company Code
                                    </td>
                                    <td style="width: 20px;">
                                        &nbsp;
                                    </td>
                                    <td class="k-tooltip-bottom">
                                        <span id="CompanyCode" style="color: Blue; font-size: 13pt;"></span>
                                    </td>
                                </tr>
                                <tr style="height: 30px;">
                                    <td class="k-tooltip-bottom">
                                        Company Name
                                    </td>
                                    <td>
                                        &nbsp;
                                    </td>
                                    <td class="k-tooltip-bottom">
                                        <span id="CompanyName" style="color: Blue; font-size: 13pt;"></span>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="k-tooltip-bottom">
                                        Contact Person
                                    </td>
                                    <td>
                                        &nbsp;
                                    </td>
                                    <td class="k-tooltip-bottom">
                                        <input type="text" name="ContactPerson" id="ContactPerson" 
                                            class="k-textbox" style="width: 95%;" />
                                        <span class="fake">*
                                        </span>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="k-tooltip-bottom">
                                        Contact Phone
                                    </td>
                                    <td>
                                        &nbsp;
                                    </td>
                                    <td class="k-tooltip-bottom">
                                        <input type="text" name="ContactPhone" id="ContactPhone" 
                                            class="k-textbox" style="width: 95%;" />
                                        <span class="fake">*
                                        </span>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="k-tooltip-bottom" valign="top">
                                        Address
                                    </td>
                                    <td>
                                        &nbsp;
                                    </td>
                                    <td class="k-tooltip-bottom">
                                        <textarea rows="5" name="Address" id="Address" 
                                            class="k-textbox" style="width: 95%;"> </textarea>
                                        <span class="fake">*
                                        </span>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="k-tooltip-bottom" valign="top">
                                        &nbsp;
                                    </td>
                                    <td>
                                        &nbsp;
                                    </td>
                                    <td class="k-tooltip-bottom">
                                        <button type="button" id="btnUpdateProfile" onclick="UpdateConpanyProfile();" class="k-button k-button-icontext k-primary"
                                            style="width: 120px;">
                                            <span class="k-icon k-update"></span>Update</button>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="k-tooltip-bottom" valign="top">
                                        &nbsp;
                                    </td>
                                    <td>
                                        &nbsp;
                                    </td>
                                    <td class="k-tooltip-bottom">
                                        <span id="errMsgProfile" />
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </div>
                </div>
            </td>
            <td valign="top">
                <div id="sidebar">
                    <div id="profile" class="widget">
                        <h3 class="style2">
                            Company Setting</h3>
                        <div>
                            <table style="width: 100%;">
                                <tr>
                                    <td class="k-tooltip-bottom" style="width: 200px;">
                                        Point Expire Type
                                    </td>
                                    <td class="k-tooltip-bottom" style="width: 20px;">
                                        &nbsp;
                                    </td>
                                    <td class="k-tooltip-bottom">
                                        <input type="text" name="PointExpireType" required="required" validationmessage="Pls select Point Expire Type."
                                            id="PointExpireType" style="width: 50%;" />
                                        <span class="k-invalid-msg" data-for="PointExpireType"></span><span class="fake">*
                                        </span>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="k-tooltip-bottom">
                                        Point Expire Fixed Date
                                    </td>
                                    <td class="k-tooltip-bottom">
                                        &nbsp;
                                    </td>
                                    <td class="k-tooltip-bottom">
                                        <input type="text" name="PointExpireFixedDate" required="required" validationmessage="Pls select Point Expire Fixed Date."
                                            id="PointExpireFixedDate" style="width: 50%;" />
                                        <span class="k-invalid-msg" data-for="PointExpireFixedDate"></span><span class="fake">
                                            * </span>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="k-tooltip-bottom">
                                        Point Expire Days
                                    </td>
                                    <td class="k-tooltip-bottom">
                                        &nbsp;
                                    </td>
                                    <td class="k-tooltip-bottom">
                                        <input type="text" name="PointExpireDays" required="required" validationmessage="Pls select  Point Expire Days."
                                            id="PointExpireDays" style="width: 50%;" />
                                        <span class="k-invalid-msg" data-for="PointExpireDays"></span><span class="fake">*
                                        </span>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="k-tooltip-bottom">
                                       Point Conflict Method
                                    </td>
                                    <td class="k-tooltip-bottom">
                                        &nbsp;
                                    </td>
                                    <td class="k-tooltip-bottom">
                                        <input type="text" name="PointConflictMethod" required="required" validationmessage="Pls select Point Conflict Method."
                                            id="PointConflictMethod" style="width: 50%;" />
                                        <span class="k-invalid-msg" data-for="PointConflictMethod"></span><span class="fake">*
                                        </span>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="k-tooltip-bottom">
                                        Point Change Action
                                    </td>
                                    <td class="k-tooltip-bottom">
                                        &nbsp;
                                    </td>
                                    <td class="k-tooltip-bottom">
                                        <input type="text" name="PointChangeAction" required="required" validationmessage="Pls select Point Change Action."
                                            id="PointChangeAction" style="width: 50%;" />
                                        <span class="k-invalid-msg" data-for="PointChangeAction"></span><span class="fake">*
                                        </span>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="k-tooltip-bottom">
                                        Grade Method
                                    </td>
                                    <td class="k-tooltip-bottom">
                                        &nbsp;
                                    </td>
                                    <td class="k-tooltip-bottom">
                                        <input type="text" name="GradeMethod" required="required" validationmessage="Pls select Grade Method."
                                            id="GradeMethod" style="width: 50%;" />
                                        <span class="k-invalid-msg" data-for="GradeMethod"></span><span class="fake">* </span>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="k-tooltip-bottom">
                                        Promotion Conflict Method
                                    </td>
                                    <td class="k-tooltip-bottom">
                                        &nbsp;
                                    </td>
                                    <td class="k-tooltip-bottom">
                                        <input type="text" name="PromotionConflictMethod" required="required" validationmessage="Pls select Promotion Conflict Method."
                                            id="PromotionConflictMethod" style="width: 50%;" />
                                        <span class="k-invalid-msg" data-for="PromotionConflictMethod"></span><span class="fake">* </span>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="k-tooltip-bottom">
                                        &nbsp;
                                    </td>
                                    <td class="k-tooltip-bottom">
                                        &nbsp;
                                    </td>
                                    <td class="k-tooltip-bottom">
                                        <button type="button" id="btnUpdateSetting" onclick="UpdateConpanySetting();" class="k-button k-button-icontext k-primary"
                                            style="width: 120px;">
                                            <span class="k-icon k-update"></span>Update</button>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="k-tooltip-bottom">
                                        &nbsp;
                                    </td>
                                    <td class="k-tooltip-bottom">
                                        &nbsp;
                                    </td>
                                    <td class="k-tooltip-bottom">
                                        <span id="errMsgSetting" />
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </div>
                </div>
            </td>
        </tr>
    </table>
    <style type="text/css">
        .dash-head
        {
            width: 970px;
            height: 80px;
            background-color: #222;
            position: relative;
        }
        
        .dash-head .k-rpanel-toggle
        {
            position: absolute;
            width: 40px;
            height: 40px;
            top: 20px;
            left: 20px;
        }
        
        .panel-wrap
        {
            max-width: 968px;
            background-color: #f5f5f5;
            border: 1px solid #e5e5e5;
            height: 300px;
        }
        
        #sidebar
        {
            margin: 0;
            /*padding: 20px 0 20px 20px;*/
            vertical-align: top;
        }
        
        
        #main-content
        {
            margin: 0;
            padding: 20px;
            min-height: 580px;
            vertical-align: top;
        }
        
        /* WIDGETS */
        .widget
        {
            margin: 0 0 20px;
            padding: 0;
            background-color: #ffffff;
            border: 1px solid #e7e7e7;
            border-radius: 3px;
            /*margin-right: 20px;*/
            height: 450px;
        }
        
        .widget div
        {
            padding: 10px;
            min-height: 50px;
        }
        
        .widget h3
        {
            font-size: 12px;
            padding: 8px 10px;
            text-transform: uppercase;
            border-bottom: 1px solid #e7e7e7;
        }
        
        .widget h3 span
        {
            float: right;
        }
        
        .widget h3 span:hover
        {
            cursor: pointer;
            background-color: #e7e7e7;
            border-radius: 20px;
        }
        
        /* PROFILE */
        .profile-photo
        {
            width: 80px;
            height: 80px;
            margin: 10px auto;
            border-radius: 100px;
            border: 1px solid #e7e7e7;
            background: url('../content/web/Customers/ISLAT.jpg') no-repeat 50% 50%;
        }
        
        #profile div
        {
            text-align: center;
        }
        
        #profile h4
        {
            width: auto;
            margin: 0 0 5px;
            font-size: 1.2em;
            color: #1f97f7;
        }
        
        #profile p
        {
            margin: 0 0 10px;
        }
        
        /* BLOGS & NEWS */
        #blogs div, #news div
        {
            padding: 0 20px 20px;
        }
        
        #teammates h4, #blogs h4, #news h4
        {
            width: auto;
            margin: 20px 0 2px;
            font-size: 1.4em;
            color: #1f97f7;
            font-weight: normal;
        }
        
        .blog-info
        {
            margin: 0 0 10px;
            font-size: .9em;
            color: #787878;
        }
        
        #sidebar #blogs h4
        {
            font-size: 1em;
        }
        
        #sidebar #blogs p
        {
            display: none;
        }
        
        #sidebar #blogs .blog-info
        {
            display: block;
        }
        
        #main-content #news h4
        {
            font-size: 1.2em;
            line-height: 1.4em;
        }
        
        #main-content #news h4 span
        {
            display: block;
            float: left;
            width: 100px;
            color: #000;
            padding-right: 10px;
        }
        
        #sidebar #news h4
        {
            font-size: 1em;
        }
        
        #sidebar #news h4 span
        {
            display: block;
            margin-bottom: 3px;
            color: #000;
        }
        
        /* TEAMMATES */
        .team-mate:after
        {
            content: ".";
            display: block;
            height: 0;
            line-height: 0;
            clear: both;
            visibility: hidden;
        }
        
        #teammates .team-mate h4
        {
            font-size: 1.4em;
            font-weight: normal;
            margin-top: 12px;
        }
        
        .team-mate p
        {
            margin: 0;
        }
        
        .team-mate img
        {
            float: left;
            margin: 0 15px 0 0;
            border: 1px solid #e7e7e7;
            border-radius: 60px;
        }
        .style2
        {
            color: #CC3300;
            font-weight: 700;
        }
    </style>
</asp:Content>
